/**
 * Created by Elsa on 2017/8/16.
 */
layui.define(['jquery', 'layer','paging', 'code','form','element','upload','laydate'], function(exports){
    var form = layui.form();
    var index;

    layui.code();
    var $ = layui.jquery,
        paging = layui.paging(),
        layer = layui.layer,
        upload = layui.upload,
        laydate = layui.laydate,
        element = layui.element(); //Tab的切换功能，切换事件监听等，需要依赖element模块

    var therole = "";

    $.ajax({
        type:"GET",
        url:contextPath+"/personal/role",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (data) {
            therole = data.role;
            if(data.role=="管理员"||data.role=="船厂"){
                $('#add').show();
            }
        },
        error: function (e) {
        }
    });

    paging.init({
        url: contextPath + "/project/const/all", //地址
        elem: '#con', //内容容器
        type: 'GET',
        //new
        key: '#s_type',
        value: '#s_value',
        params: { //发送到服务端的参数
        },
        tempElem: '#conTemp', //模块容器
        pageConfig: { //分页参数配置
            elem: '#page', //分页容器
            pageSize: 10 //分页大小
        },
        success: function() { //渲染成功的回调
            if(therole == "管理员"){
                $('.moress').show();
                $('.moress1').show();
                $('.checklist').show();
                $('.doc').show();
                $('.itemOp').show();
            }else if(therole == "负责人"){
                $('.moress').show();
                $('.moress1').show();
                $('.checklist').show();
                $('.doc').show();
            }else if(therole == "验船师"){
                $('.moress').show();
                $('.checklist').show();
                $('.log').show();
                $('.doc').show();
            }else if(therole == "船厂"){
                $('.moress').show();
                $('.checklist').show();
                $('.doc').show();
            }else if(therole == "船东"){
                $('.moress').show();
                $('.checklist').show();
                $('.doc').show();
            }else{

            }
        },
        fail: function(msg) { //获取数据失败的回调
        },
        complate: function() { //完成的回调
        },
    });

    $("body").on("click",".itemOp",function () {
        var inspnum = $(this).data('id');
        layer.open({
            type:1,
            title: '选择操作'
            ,id: 'itemOp' //设定一个id，防止重复弹出
            ,area: ['250px', '150px']
            ,content: '<div style="padding-left: 50px ;padding-top:20px;padding-bottom:25px;width:200px">' +
            '<a href="javascript:;" class="layui-btn layui-btn-normal layui-btn-small forbidd" data-id="'+inspnum+'">禁用</a>' +
            '<a href="javascript:;" class="layui-btn layui-btn-normal layui-btn-warm layui-btn-small reneww" data-id="'+inspnum+'">恢复</a>' +
            '<a href="javascript:;" class="layui-btn layui-btn-normal layui-btn-danger layui-btn-small deletee" data-id="'+inspnum+'">删除</a>' +
            '</div>'
        });
    });


    $("body").on("click",".checklist",function(){
        var inspnum = $(this).data('id');
        layer.closeAll();
        $.ajax({
            type: "GET",
            url: contextPath + "/project/const/" + inspnum,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (data) {
                if(data.auditstate&&data.auditstate=="同意受理"){

                    parent.layui.element().tabAdd('demo', {
                        title: inspnum+' 报检单列表',
                        content:'<iframe frameborder=0 width="100%" height="700px" marginheight=0 marginwidth=0 scrolling=auto src=CheckList/ConstCheckList.html?inspnum='+inspnum+'></iframe>',
                        id: 'flag'+ inspnum
                    });
                    parent.layui.element().tabChange('demo', 'flag'+ inspnum);
                    parent.layui.element().init();
                }else if(data.auditstate&&data.auditstate=="不予受理"){
                    layer.msg('申请表已审核<br>不予受理' , {
                        time:false,
                        btn:"确定",
                        btnAlign: 'c'
                    });
                }else{
                    layer.msg('申请表未审核' , {
                        time:false,
                        btn:"确定",
                        btnAlign: 'c'
                    });
                }
            },
            error: function (e) {
            }
        });
    });

    $("body").on("click",".log",function(){
        var inspnum = $(this).data('id');
        layer.closeAll();
        parent.layui.element().tabAdd('demo', {
            title: inspnum+' 日志列表',
            content:'<iframe frameborder=0 width="100%" height="700px" marginheight=0 marginwidth=0 scrolling=auto src=LogList/ConstLogList.html?inspnum='+inspnum+'></iframe>',
            id: 'log'+ inspnum
        });
        parent.layui.element().tabChange('demo', 'log'+ inspnum);
        parent.layui.element().init();

    });

    $("body").on("click",".doc",function(){
        var inspnum = $(this).data('id');

        parent.layui.element().tabAdd('demo', {
            title: inspnum+' 文档列表',
            content:'<iframe frameborder=0 width="100%" height="700px" marginheight=0 marginwidth=0 scrolling=auto src=DocList/ConstDocList.html?inspnum='+inspnum+'></iframe>',
            id: 'doc'+ inspnum
        });
        parent.layui.element().tabChange('demo', 'doc'+ inspnum);
        parent.layui.element().init();

    });

    $("body").on("click",".forbidd",function(){
        var inspnum = $(this).data('id');
        layer.closeAll();
         layer.alert('是否禁用该项目?',{
            skin: 'layui-layer-molv' //样式类名  自定义样式
            ,closeBtn: 1    // 是否显示关闭按钮
            ,anim: 1 //动画类型
            ,btn: ['确定','取消'] //按钮
            ,btnAlign:'c'
            ,icon: 6    // icon
        },function(){
            $.ajax({
                type:"PUT",
                url:contextPath+"/project/const/forbid/" + inspnum,
                contentType: "application/json; charset=utf-8",
                dataType:"json",
                success:function (data) {
                    console.log(data.message);
                    if(data.message == "禁用建造检验成功!"){
                        layer.msg('禁用成功!<br>页面将在1秒后刷新...', {time: 1000});
                        setTimeout(function(){window.location.reload();},1000);
                    } else {
                        layer.msg(data.message, {
                            time:false,
                            btn:"确定",
                            btnAlign: 'c'
                        });
                    }
                },
                error:function (e) {
                }
            });
        });
    });

    $("body").on("click",".reneww",function(){
        var inspnum = $(this).data('id');
        layer.closeAll();
        layer.alert('是否恢复该项目?',{
            skin: 'layui-layer-molv' //样式类名  自定义样式
            ,closeBtn: 1    // 是否显示关闭按钮
            ,anim: 1 //动画类型
            ,btn: ['确定','取消'] //按钮
            ,btnAlign:'c'
            ,icon: 6    // icon
        },function(){
            $.ajax({
                type:"PUT",
                url:contextPath+"/project/const/renew/" + inspnum,
                contentType: "application/json; charset=utf-8",
                dataType:"json",
                success:function (data) {
                    console.log(data.message);
                    if(data.message == "恢复建造检验成功!"){
                        layer.msg('恢复成功!<br>页面将在1秒后刷新...', {time: 1000});
                        setTimeout(function(){window.location.reload();},1000);
                    } else {
                        layer.msg(data.message, {
                            time: false,
                            btn:"确定",
                            btnAlign: 'c'
                        });
                    }
                },
                error:function (e) {
                }
            });
        });
    });

    $("body").on("click",".deletee",function(){
        var inspnum = $(this).data('id');
        layer.closeAll();
        layer.alert('是否删除该项目?',{
            skin: 'layui-layer-molv' //样式类名  自定义样式
            ,closeBtn: 1    // 是否显示关闭按钮
            ,anim: 1 //动画类型
            ,btn: ['确定','取消'] //按钮
            ,btnAlign:'c'
            ,icon: 6    // icon
        },function(){
            $.ajax({
                type:"PUT",
                url:contextPath+"/project/const/delete/" + inspnum,
                contentType: "application/json; charset=utf-8",
                dataType:"json",
                success:function (data) {
                    if(data.message == "删除建造检验成功!"){
                        layer.msg('删除成功!<br>页面将在1秒后刷新...');
                        setTimeout(function(){window.location.reload();},1000);
                    } else {
                        layer.msg(data.message, {
                            time: false,
                            btn:"确定",
                            btnAlign: 'c'
                        });
                    }
                },
                error:function (e) {
                }
            });
        });
    });

    $("body").on("click",".moress",function(){
        var inspnum = $(this).data('id');
        layer.closeAll();
        $.ajax({
            type: "GET",
            url: contextPath + "/project/const/" + inspnum,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (data) {
                console.log(data);
                $.get('ConstDetailsForm.html',function(ConstDetailsForm) {
                    index = layer.open({
                        type: 1,
                        title: '审核申请表',
                        content: ConstDetailsForm,
                        area: ['auto', '600px'],
                        maxmin: false,
                        success:function (layero,index) {

                            layero.find("#closex").on("click",function () {
                                layer.closeAll();
                            });
                            layero.find("#closes").on("click",function () {
                                layer.closeAll();
                            });

                            var ctinfos = data.ctname+"/"+data.ctusername;
                            var ljinfos = data.ljname+"/"+data.ljusername;
                            var dqinfos = data.dqname+"/"+data.dqusername;
                            var cdinfos = data.cdname+"/"+data.cdusername;

                            $.ajax({
                                type:"GET",
                                url:contextPath+"/user/cd",
                                contentType: "application/json; charset=utf-8",
                                dataType:"json",
                                success:function (data) {
                                    console.log(data[0].name);
                                    for(var i=0; i<data.length; i++){
                                        $('select[name="cdinfo"]').append("<option value='"+data[i].name+"/"+data[i].username+"'>"+data[i].name+"/"+data[i].username+"</option>");
                                    }
                                    $('select[name="cdinfo"]').val(cdinfos);
                                    form.render();
                                },
                                error:function (e) {
                                }
                            });

                            $.ajax({
                                type:"GET",
                                url:contextPath+"/user/ycs",
                                contentType: "application/json; charset=utf-8",
                                data: {type:"ct", value:"船体"},
                                dataType:"json",
                                success:function (data) {
                                    console.log(data[0].name);
                                    for(var i=0; i<data.length; i++){
                                        $('select[name="ctinfo"]').append("<option value='"+data[i].name+"/"+data[i].username+"'>"+data[i].name+"/"+data[i].username+"</option>");
                                    }
                                    $('select[name="ctinfo"]').val(ctinfos);
                                    form.render();
                                },
                                error:function (e) {

                                }
                            });

                            $.ajax({
                                type:"GET",
                                url:contextPath+"/user/ycs",
                                contentType: "application/json; charset=utf-8",
                                data: {type:"lj", value:"轮机"},
                                dataType:"json",
                                success:function (data) {
                                    console.log(data[0].name);
                                    for(var i=0; i<data.length; i++){
                                        $('select[name="ljinfo"]').append("<option value='"+data[i].name+"/"+data[i].username+"'>"+data[i].name+"/"+data[i].username+"</option>");
                                    }
                                    $('select[name="ljinfo"]').val(ljinfos);
                                    form.render();
                                },
                                error:function (e) {

                                }
                            });

                            $.ajax({
                                type:"GET",
                                url:contextPath+"/user/ycs",
                                contentType: "application/json; charset=utf-8",
                                data: {type:"dq", value:"电气"},
                                dataType:"json",
                                success:function (data) {
                                    console.log(data[0].name);
                                    for(var i=0; i<data.length; i++){
                                        $('select[name="dqinfo"]').append("<option value='"+data[i].name+"/"+data[i].username+"'>"+data[i].name+"/"+data[i].username+"</option>");
                                    }
                                    $('select[name="dqinfo"]').val(dqinfos);
                                    form.render();
                                },
                                error:function (e) {

                                }
                            });
                            
                            if(data.info1){
                                $('input[name="info1"]').attr("checked",true);
                                $('input[name="info1num"]').css("visibility",'visible');
                                $('#download1').css("visibility",'visible');
                                $('#download1').attr('href',contextPath+'/download?file='+data.info1adr);
                            }else{
                                $('input[name="info1"]').attr("checked",false);
                            }
                            if(data.info2){
                                $('input[name="info2"]').attr("checked",true);
                                $('input[name="info2num"]').css("visibility",'visible');
                                $('#download2').css("visibility",'visible');
                                $('#download2').attr('href',contextPath+'/download?file='+data.info2adr);
                            }else{
                                $('input[name="info2"]').attr("checked",false);
                            }
                            if(data.info3){
                                $('input[name="info3"]').attr("checked",true);
                                $('#download3').css("visibility",'visible');
                                $('#download3').attr('href',contextPath+'/download?file='+data.info3adr);
                            }else{
                                $('input[name="info3"]').attr("checked",false);
                            }
                            if(data.info4){
                                $('input[name="info4"]').attr("checked",true);
                                $('input[name="info4name"]').css("visibility",'visible');
                                $('#download4').css("visibility",'visible');
                                $('#download4').attr('href',contextPath+'/download?file='+data.info4adr);
                            }else{
                                $('input[name="info4"]').attr("checked",false);
                            }

                            $('input[name="shipname"]').attr("value",data.shipname);
                            $('input[name="insptype"]').attr("value",data.insptype);
                            $('select[name="insptype"]').val(data.insptype);
                            $('input[name="shiplength"]').attr("value",data.shiplength);
                            $('input[name="grosston"]').attr("value",data.grosston);
                            $('input[name="hostpower"]').attr("value",data.hostpower);
                            $('input[name="region"]').attr("value",data.region);
                            $('select[name="region"]').val(data.region);
                            $('input[name="shipstops"]').attr("value",data.shipstops);
                            $('input[name="shiptype"]').attr("value",data.shiptype);
                            $('input[name="designunit"]').attr("value",data.designunit);
                            $('input[name="figurenum"]').attr("value",data.figurenum);
                            $('input[name="approvalnum"]').attr("value",data.approvalnum);
                            $('input[name="figuredate"]').attr("value",data.figuredate);
                            $('input[name="schddate"]').attr("value",data.schddate);
                            $('input[name="cdinfo"]').attr("value",cdinfos);
                            $('input[name="ccpronum"]').attr("value",data.ccpronum);
                            $('input[name="info1num"]').attr("value",data.info1num);
                            $('input[name="info2num"]').attr("value",data.info2num);
                            $('input[name="info4name"]').attr("value",data.info4name);
                            $('textarea[name="additional"]').val(data.additional);
                            $('input[name="apunitname"]').attr("value",data.apunitname);
                            $('input[name="fax"]').attr("value",data.fax);
                            $('input[name="zipcode"]').attr("value",data.zipcode);
                            $('input[name="crecode"]').attr("value",data.crecode);
                            $('input[name="writedate"]').attr("value",data.writedate);
                            $('input[name="ccadr"]').attr("value",data.ccadr);
                            $('input[name="writename"]').attr("value",data.writename);
                            var ccstr = data.ccinfo.split('/');
                            $('input[name="ccinfo"]').attr("value",ccstr[0]);
                            $('input[name="ccphone"]').attr("value",ccstr[1]);
                            $('textarea[name="remarks"]').val(data.remarks);
                            
                            if(data.auditstate){
                                $('input[name="auditstate"]').attr("value",data.auditstate);
                                $('select[name="auditstate"]').val(data.auditstate);
                                $('input[name="auditdate"]').attr("value",data.auditdate);
                                if(chickInspnum(inspnum)){
                                    $('#ainspnumlabel').html("检验编号");
                                    $('input[name="ainspnum"]').attr("value",data.inspnum);
                                    $('input[name="ainspnum"]').show();
                                }
                                if(data.auditstate == "不予受理"){
                                    $('textarea[name="auditopn"]').val(data.auditopn);
                                    $('textarea[name="auditopn"]').show();
                                } else{
                                    $('.constructionGroup').show();
                                    if(data.headman==1){
                                        $('input:radio[name="headman1"][value="1"]').attr("checked",true);
                                        $('input:radio[name="headman2"][value="1"]').attr("checked",true);
                                    }else if(data.headman==2){
                                        $('input:radio[name="headman1"][value="2"]').attr("checked",true);
                                        $('input:radio[name="headman2"][value="2"]').attr("checked",true);
                                    }else if(data.headman==3){
                                        $('input:radio[name="headman1"][value="3"]').attr("checked",true);
                                        $('input:radio[name="headman2"][value="3"]').attr("checked",true);
                                    }else{
                                    }
                                    $('input[name="ctinfo"]').attr('value',ctinfos);
                                    $('input[name="ljinfo"]').attr('value',ljinfos);
                                    $('input[name="dqinfo"]').attr('value',dqinfos);
                                }
                            }else{
                                $('.reviewResult').hide();
                            }
                            $.ajax({
                                type:"GET",
                                url:contextPath+"/personal/role",
                                contentType: "application/json; charset=utf-8",
                                dataType: "json",
                                success: function (data) {
                                    console.log(data.role);
                                    if(data.role!="管理员"){
                                        $('#edit').hide();
                                    }
                                },
                                error: function (e) {

                                }
                            });
                            if(data.state=="禁用"){
                                $('#edit').hide();
                            }

                            //打印
                            $('#su').on('click',function () {
                               window.open('../../print/const/ConstAppForm/ConstAForm.html?inspnum='+inspnum);
                            });

                            $('#edit').on('click',function () {
                                $('#xxx').hide();
                                $('#sss').show();
                                $('#insptype1').hide();
                                $('#insptype2').show();
                                $('#region1').hide();
                                $('#region2').show();
                                $('#auditstate1').hide();
                                $('#auditstate2').show();
                                $('.headman1').hide();
                                $('.headman2').show();
                                $('.groupinfo1').hide();
                                $('.groupinfo2').show();

                                $('input[name="shipname"]').attr('disabled', false);
                                $('input[name="insptype"]').attr('disabled', false);
                                $('input[name="shiplength"]').attr('disabled', false);
                                $('input[name="grosston"]').attr('disabled', false);
                                $('input[name="hostpower"]').attr('disabled', false);
                                $('input[name="region"]').attr('disabled', false);
                                $('input[name="shipstops"]').attr('disabled', false);
                                $('input[name="shiptype"]').attr('disabled', false);
                                $('input[name="designunit"]').attr('disabled', false);
                                $('input[name="figurenum"]').attr('disabled', false);
                                $('input[name="approvalnum"]').attr('disabled', false);
                                $('input[name="figuredate"]').attr('disabled', false);
                                $('input[name="schddate"]').attr('disabled', false);
                                $('input[name="ccpronum"]').attr('disabled', false);
                                $('textarea[name="additional"]').attr('disabled', false)
                                $('textarea[name="remarks"]').attr('disabled', false);
                                $('input[name="headman"]').attr('disabled',false);
                                $('input[name="auditstate"]').attr('disabled', false);
                                $('textarea[name="auditopn"]').attr('disabled', false);
                                $('input[name="auditdate"]').attr('disabled', false);

                                $('input[name="shipname"]').attr('class', 'layui-input');
                                $('input[name="insptype"]').attr('class', 'layui-input');
                                $('input[name="shiplength"]').attr('class', 'layui-input');
                                $('input[name="grosston"]').attr('class', 'layui-input');
                                $('input[name="hostpower"]').attr('class', 'layui-input');
                                $('input[name="region"]').attr('class', 'layui-input');
                                $('input[name="shipstops"]').attr('class', 'layui-input');
                                $('input[name="shiptype"]').attr('class', 'layui-input');
                                $('input[name="designunit"]').attr('class', 'layui-input');
                                $('input[name="figurenum"]').attr('class', 'layui-input');
                                $('input[name="approvalnum"]').attr('class', 'layui-input');
                                $('input[name="figuredate"]').attr('class', 'layui-input');
                                $('input[name="schddate"]').attr('class', 'layui-input');
                                $('input[name="ccpronum"]').attr('class', 'layui-input');
                                $('textarea[name="additional"]').attr('class', 'layui-textarea');
                                $('textarea[name="remarks"]').attr('class', 'layui-textarea');
                                $('input[name="auditstate"]').attr('class', 'layui-input');
                                $('textarea[name="auditopn"]').attr('class', 'layui-textarea');
                                $('input[name="auditdate"]').attr('class', 'layui-input');
                            });

                            form.on('select(type)', function(data){
                                if(chickInspnum(inspnum)){
                                    if(data.value == '不予受理'){
                                        $('.constructionGroup').hide();
                                        $('textarea[name="auditopn"]').show();
                                        form.render();  
                                    }else if(data.value == '同意受理'){
                                        $('.constructionGroup').show();
                                        $('textarea[name="auditopn"]').hide();
                                        form.render();
                                    }else{

                                    }
                                }else{
                                    $('input[name="ainspnum"]').attr('disabled', false);
                                    $('input[name="ainspnum"]').attr('class', 'layui-input');
                                    if(data.value == '不予受理'){
                                        $('.constructionGroup').hide();
                                        $('#ainspnumlabel').html("");
                                        $('input[name="ainspnum"]').hide();
                                        $('textarea[name="auditopn"]').show();
                                        form.render();
                                    }else if(data.value == '同意受理'){
                                        $('.constructionGroup').show();
                                        $('#ainspnumlabel').html("检验编号");
                                        $('input[name="ainspnum"]').show();
                                        $('textarea[name="auditopn"]').hide();
                                        form.render();
                                    }
                                }
                            });

                            layero.find('input[name="shiplength"]').on("blur",function () {
                                var s = toDecimal2($(this).val());
                                if(s){
                                    $('input[name="shiplength"]').val(s);
                                }else{
                                    $('input[name="shiplength"]').val("");
                                }
                            });

                            layero.find('input[name="grosston"]').on("blur",function () {
                                var s = Math.round($(this).val());
                                if(s){
                                    $('input[name="grosston"]').val(s);
                                }else{
                                    $('input[name="grosston"]').val("");
                                }
                            });

                            layero.find('input[name="hostpower"]').on("blur",function () {
                                var s = toDecimal2($(this).val());
                                if(s){
                                    $('input[name="hostpower"]').val(s);
                                }else{
                                    $('input[name="hostpower"]').val("");
                                }
                            });
                            
                            form.on('select(regionfilter)', function(data){
                                if(data.value == '其他'){
                                    layer.prompt({
                                        formType: 0,
                                        value:'',
                                        maxlength: 10,
                                        title: '请输入其他航行区域'
                                    }, function(value, index, elem){
                                        console.log(value);
                                        $('select[name="region"]').append("<option value='"+value+"'>"+value+"</option>");
                                        $('select[name="region"]').val(value);
                                        layer.close(index);
                                        $('select[name="region"] option').each(function() {
                                            var val = $(this).val();
                                            if($("select[name='region'] option[value='" + val + "']").length > 1 ){
                                                $("select[name='region'] option[value='" + val + "']:gt(0)").remove();
                                            }
                                        });
                                        form.render();
                                    });  
                                }
                            });

                            form.on('select(insptypefilter)', function(data){
                                if(data.value == '其他'){
                                    layer.prompt({
                                        formType: 0,
                                        value:'',
                                        maxlength: 10,
                                        title: '请输入其他检验类型'
                                    }, function(value, index, elem){
                                        console.log(value);
                                        $('select[name="insptype"]').append("<option value='"+value+"'>"+value+"</option>");
                                        $('select[name="insptype"]').val(value);
                                        layer.close(index);
                                        $('select[name="insptype"] option').each(function() {
                                            var val = $(this).val();
                                            if($("select[name='insptype'] option[value='" + val + "']").length > 1 ){
                                                $("select[name='insptype'] option[value='" + val + "']:gt(0)").remove();
                                            }
                                        });
                                        form.render();
                                    });  
                                }
                            });

                            $('#submit').on('click',function () {
                                var ss = new Object();

                                ss.shipname = $('input[name="shipname"]').val();
                                ss.insptype = $('select[name="insptype"] option:selected').val();
                                ss.inspnum = inspnum;
                                ss.shiplength = $('input[name="shiplength"]').val();
                                ss.grosston = $('input[name="grosston"]').val();
                                ss.hostpower = $('input[name="hostpower"]').val();
                                ss.region = $('select[name="region"] option:selected').val();
                                ss.shipstops = $('input[name="shipstops"]').val();
                                ss.shiptype = $('input[name="shiptype"]').val();
                                ss.designunit = $('input[name="designunit"]').val();
                                ss.figurenum = $('input[name="figurenum"]').val();
                                ss.approvalnum = $('input[name="approvalnum"]').val(); 
                                ss.figuredate = $('input[name="figuredate"]').val();
                                ss.schddate = $('input[name="schddate"]').val();
                                if($('select[name="cdinfo"] option:selected').val()){
                                    ss.cdinfo = $('select[name="cdinfo"] option:selected').val();
                                }else{
                                    ss.cdinfo = "";
                                }
                                ss.ccpronum = $('input[name="ccpronum"]').val();
                                ss.additional = $('textarea[name="additional"]').val();
                                ss.apunitname = $('input[name="apunitname"]').val();
                                ss.fax = $('input[name="fax"]').val();
                                ss.zipcode = $('input[name="zipcode"]').val();
                                ss.crecode = $('input[name="crecode"]').val();
                                ss.writedate = $('input[name="writedate"]').val();
                                ss.ccadr = $('input[name="ccadr"]').val();
                                ss.writename = $('input[name="writename"]').val();
                                ss.ccinfo = $('input[name="ccinfo"]').val()+"/"+$('input[name="ccphone"]').val();
                                ss.remarks = $('textarea[name="remarks"]').val();

                                var message1="", message2="";
                                console.log(JSON.stringify(ss));

                                $.ajax({
                                    type:"PUT",
                                    url:contextPath+"/project/const/update/cc",
                                    contentType: "application/json; charset=utf-8",
                                    async: false,
                                    data:JSON.stringify(ss),
                                    dataType:"json",
                                    success:function (data) {
                                        message1 = data.message;
                                    },
                                    error:function (e) {
                                    }
                                });

                                if($('select[name="auditstate"] option:selected').val()){
                                    var sss = new Object();

                                    sss.inspnum = inspnum;
                                    sss.auditstate = $('select[name="auditstate"] option:selected').val();
                                    if(chickInspnum(inspnum)){
                                        sss.ainspnum = "";
                                    }else{
                                        sss.ainspnum = $('input[name="ainspnum"]').val();
                                    }
                                    if(sss.auditstate=='不予受理'){
                                        sss.auditopn = $('textarea[name="auditopn"]').val();
                                        sss.headman = 0;
                                        sss.ctinfo = "";
                                        sss.dqinfo = "";
                                        sss.ljinfo = "";
                                    }else{
                                        sss.auditopn = "";
                                        sss.headman = $('input[name="headman2"]:checked').val();
                                        sss.ctinfo = $('select[name="ctinfo"] option:selected').val();
                                        sss.dqinfo = $('select[name="dqinfo"] option:selected').val();
                                        sss.ljinfo = $('select[name="ljinfo"] option:selected').val();
                                    }

                                    console.log(JSON.stringify(sss));
                                    $.ajax({
                                        type:"PUT",
                                        url:contextPath+"/project/const/update/cjc",
                                        contentType: "application/json; charset=utf-8",
                                        async: false,
                                        data: JSON.stringify(sss),
                                        dataType:"json",
                                        success:function (data) {
                                            message2 = data.message;
                                        },
                                        error:function (e) {
                                        }
                                    });
                                }

                                if(message2 != ""){
                                    if(message1 == "更新成功!"&message2 == "更新成功!"){
                                        layer.msg('建造检验申请表更新成功!<br>页面将在1秒后刷新...');
                                        setTimeout(function(){window.location.reload();},1000);
                                    }else{
                                        if(message1 == "更新成功!"){
                                            message1 = "新建申请表模块 "+message1;
                                        }else{
                                            message1 = "<b style='color:red'>新建申请表模块 更新失败!<br>"+message1+"</b>";
                                        }
                                        if(message2 == "更新成功!"){
                                            message2 = "审核申请表模块 "+message2;
                                        }else{
                                            message2 = "<b style='color:red'>审核申请表模块 更新失败!<br>"+message2+"</b>";
                                        }
                                        layer.msg(message1+'<br><br>'+message2, {
                                            time: false,
                                            btn:"确定",
                                            btnAlign: 'c'
                                        });
                                    }
                                }else{
                                    if(message1 == "更新成功!"){
                                        layer.msg('建造检验申请表更新成功!<br>页面将在1秒后刷新...');
                                        setTimeout(function(){window.location.reload();},1000);
                                    }else{
                                        layer.msg(message1, {
                                            time: false,
                                            btn:"确定",
                                            btnAlign: 'c'
                                        });
                                    }
                                }
                                return false;
                            });

                        },
                        yes: function(index) {
                            console.log(index);
                        },
                        full: function(elem) {
                            var win = window.top === window.self ? window : parent.window;
                            $(win).on('resize', function() {
                                var $this = $(this);
                                elem.width($this.width()).height($this.height()).css({
                                    top: 0,
                                    left: 0
                                });
                                elem.children('div.layui-layer-content').height($this.height() - 95);
                            });
                        }
                    });
                    form.render();
                });
            },
            error: function (e) {

            }
        });

    });

    $("body").on("click",".moress1",function(){
        var inspnum = $(this).data('id');
        layer.closeAll();
        $.ajax({
            type: "GET",
            url: contextPath + "/project/const/" + inspnum,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (data) {
                if(data.state=='禁用'){
                    layer.msg('该建造检验项目被禁用' , {
                        time:false,
                        btn:"确定",
                        btnAlign: 'c'
                    });
                }else if(data.auditstate){
                    layer.msg('该申请表已审核完毕<br>'+data.auditstate , {
                        time:false,
                        btn:"确定",
                        btnAlign: 'c'
                    });
                }else{
                    $.get('ConstAppForm.html',function(ConstAppForm) {
                        index = layer.open({
                            type: 1,
                            title: '审核申请表',
                            content: ConstAppForm,
                            area: ['auto', '600px'],
                            maxmin: false,
                            success:function (layero,index) {
                                if(data.info1){
                                    $('input[name="info1"]').attr("checked",true);
                                    $('input[name="info1num"]').css("visibility",'visible');
                                    $('#download1').css("visibility",'visible');
                                    $('#download1').attr('href',contextPath+'/download?file='+data.info1adr);
                                }else{
                                    $('input[name="info1"]').attr("checked",false);
                                }
                                if(data.info2){
                                    $('input[name="info2"]').attr("checked",true);
                                    $('input[name="info2num"]').css("visibility",'visible');
                                    $('#download2').css("visibility",'visible');
                                    $('#download2').attr('href',contextPath+'/download?file='+data.info2adr);
                                }else{
                                    $('input[name="info2"]').attr("checked",false);
                                }
                                if(data.info3){
                                    $('input[name="info3"]').attr("checked",true);
                                    $('#download3').css("visibility",'visible');
                                    $('#download3').attr('href',contextPath+'/download?file='+data.info3adr);
                                }else{
                                    $('input[name="info3"]').attr("checked",false);
                                }
                                if(data.info4){
                                    $('input[name="info4"]').attr("checked",true);
                                    $('input[name="info4name"]').css("visibility",'visible');
                                    $('#download4').css("visibility",'visible');
                                    $('#download4').attr('href',contextPath+'/download?file='+data.info4adr);
                                }else{
                                    $('input[name="info4"]').attr("checked",false);
                                }

                                $('input[name="shipname"]').attr("value",data.shipname);
                                $('input[name="insptype"]').attr("value",data.insptype);
                                $('input[name="shiplength"]').attr("value",data.shiplength);
                                $('input[name="grosston"]').attr("value",data.grosston);
                                $('input[name="hostpower"]').attr("value",data.hostpower);
                                $('input[name="region"]').attr("value",data.region);
                                $('input[name="shipstops"]').attr("value",data.shipstops);
                                $('input[name="shiptype"]').attr("value",data.shiptype);
                                $('input[name="designunit"]').attr("value",data.designunit);
                                $('input[name="figurenum"]').attr("value",data.figurenum);
                                $('input[name="approvalnum"]').attr("value",data.approvalnum);
                                $('input[name="figuredate"]').attr("value",data.figuredate);
                                $('input[name="schddate"]').attr("value",data.schddate);
                                $('input[name="cdinfo"]').attr("value",data.cdname+"/"+data.cdusername);
                                $('input[name="ccpronum"]').attr("value",data.ccpronum);
                                $('input[name="info1num"]').attr("value",data.info1num);
                                $('input[name="info2num"]').attr("value",data.info2num);
                                $('input[name="info4name"]').attr("value",data.info4name);
                                $('textarea[name="additional"]').val(data.additional);
                                $('input[name="apunitname"]').attr("value",data.apunitname);
                                $('input[name="fax"]').attr("value",data.fax);
                                $('input[name="zipcode"]').attr("value",data.zipcode);
                                $('input[name="crecode"]').attr("value",data.crecode);
                                $('input[name="writedate"]').attr("value",data.writedate);
                                $('input[name="ccadr"]').attr("value",data.ccadr);
                                $('input[name="writename"]').attr("value",data.writename);
                                var ccstr = data.ccinfo.split('/');
                                $('input[name="ccinfo"]').attr("value",ccstr[0]);
                                $('input[name="ccphone"]').attr("value",ccstr[1]);
                                $('textarea[name="remarks"]').val(data.remarks);

                                $('input[name="auditdate"]').attr("value",getNowFormatDate());
                                $( document ).ready(function() {
                                    $.ajax({
                                        type:"GET",
                                        url:contextPath+"/user/ycs",
                                        contentType: "application/json; charset=utf-8",
                                        data: {type:"ct", value:"船体"},
                                        dataType:"json",
                                        success:function (data) {
                                            for(var i=0; i<data.length; i++){
                                                $('select[name="ctinfo"]').append("<option value='"+data[i].name+"/"+data[i].username+"'>"+data[i].name+"/"+data[i].username+"</option>");
                                            }
                                            form.render();
                                        },
                                        error:function (e) {

                                        }
                                    });

                                    $.ajax({
                                        type:"GET",
                                        url:contextPath+"/user/ycs",
                                        contentType: "application/json; charset=utf-8",
                                        data: {type:"lj", value:"轮机"},
                                        dataType:"json",
                                        success:function (data) {
                                            for(var i=0; i<data.length; i++){
                                                $('select[name="ljinfo"]').append("<option value='"+data[i].name+"/"+data[i].username+"'>"+data[i].name+"/"+data[i].username+"</option>");
                                            }
                                            form.render();
                                        },
                                        error:function (e) {

                                        }
                                    });

                                    $.ajax({
                                        type:"GET",
                                        url:contextPath+"/user/ycs",
                                        contentType: "application/json; charset=utf-8",
                                        data: {type:"dq", value:"电气"},
                                        dataType:"json",
                                        success:function (data) {
                                            for(var i=0; i<data.length; i++){
                                                $('select[name="dqinfo"]').append("<option value='"+data[i].name+"/"+data[i].username+"'>"+data[i].name+"/"+data[i].username+"</option>");
                                            }
                                            form.render();
                                        },
                                        error:function (e) {

                                        }
                                    });
                                });

                                form.on('submit(ca)', function(data) {
                                    $(this).attr('disabled','disabled');
                                    var ConstAppForm = new Object();
                                    ConstAppForm.inspnum = inspnum;
                                    ConstAppForm.ainspnum = $('input[name="ainspnum"]').val();
                                    ConstAppForm.ctinfo = $("select[name='ctinfo'] option:selected").val();
                                    ConstAppForm.dqinfo = $("select[name='dqinfo'] option:selected").val();
                                    ConstAppForm.ljinfo = $("select[name='ljinfo'] option:selected").val();
                                    if($("input[name='headman']:checked").val()){
                                        ConstAppForm.headman = $("input[name='headman']:checked").val();
                                    }else{
                                        ConstAppForm.headman = 0;
                                    }
                                    ConstAppForm.auditstate = $("select[name='auditstate'] option:selected").val();
                                    ConstAppForm.auditopn = data.field.auditopn;
                                    console.log(JSON.stringify(ConstAppForm));

                                    $.ajax({
                                        type:"PUT",
                                        url:contextPath+"/project/const/update/cjc",
                                        contentType: "application/json; charset=utf-8",
                                        data: JSON.stringify(ConstAppForm),
                                        dataType:"json",
                                        success:function (data) {
                                            console.log(data.message);
                                            if(data.message == "更新成功!"){
                                                layer.closeAll();
                                                layer.msg('提交评审成功!<br>页面将在1秒后刷新...');
                                                setTimeout(function(){window.location.reload();},1000);
                                            } else {
                                                $('#su').attr('disabled',false);
                                                layer.msg(data.message, {
                                                    time:false,
                                                    btn:"确定",
                                                    btnAlign: 'c'
                                                });
                                                $("#all-info").html("*"+data.message);
                                            }
                                        },
                                        error:function (e) {
                                        }
                                    });

                                    return false;
                                });

                            },
                            yes: function(index) {
                                console.log(index);
                            },
                            full: function(elem) {
                                var win = window.top === window.self ? window : parent.window;
                                $(win).on('resize', function() {
                                    var $this = $(this);
                                    elem.width($this.width()).height($this.height()).css({
                                        top: 0,
                                        left: 0
                                    });
                                    elem.children('div.layui-layer-content').height($this.height() - 95);
                                });
                            }
                        });
                        form.render();
                    });
                }
            },
            error: function (e) {
            }
        });

    });

    $('body').on('click', '#closes', function(){
        layer.close(index);
        return false;
    });

    $('body').on('click', '#closex', function(){
        layer.close(index);
        return false;
    });

    $('#search').on('click', function() {
        var type = $('#search_type').val();
        var value = $('#search_value').val();
        $('#s_type').attr("value",type);
        $('#s_value').attr("value",value);
        if( value === '' || value.length === 0) {
            layer.msg('请输入关键字！',{
                time:2000
            });
            return ;
        } 
        paging.get({
            value: value,
            type: type
        });
    });

    $('#showall').on('click', function() {
        $('#search_type').val("");
        $('#search_value').val("");
        $('#s_type').removeAttr("value");
        $('#s_value').removeAttr("value");
        form.render();
        paging.get({
            value: null,
            type: null
        });
    });

    $('#add').on('click', function() {
        $.get('ConstNewItems.html', null, function(ConstNewItems) {
            layer.open({
                type: 1,
                title: '新建建造检验申请表',
                content: ConstNewItems,
                area: ['auto', '600px'],
                maxmin: false,
                success:function (layero,index) {
                    layero.find("#closex").on("click",function () {
                        layer.closeAll();
                    });

                    $.ajax({
                        type:"GET",
                        url:contextPath+"/user/cd",
                        contentType: "application/json; charset=utf-8",
                        dataType:"json",
                        success:function (data) {
                            for(var i=0; i<data.length; i++){
                                $('select[name="cdinfo"]').append("<option value='"+data[i].name+"/"+data[i].username+"'>"+data[i].name+"/"+data[i].username+"</option>");
                            }
                            form.render();
                        },
                        error:function (e) {
                        }
                    });

                    if(therole=="管理员"){
                        $('#chosecc').show();
                        $.ajax({
                            type:"GET",
                            url:contextPath+"/user/cc",
                            contentType: "application/json; charset=utf-8",
                            dataType:"json",
                            success:function (data) {
                                for(var i=0; i<data.length; i++){
                                    $('select[name="cc"]').append("<option value='"+data[i].name+"/"+data[i].username+"'>"+data[i].name+"/"+data[i].username+"</option>");
                                }
                                form.render();
                            },
                            error:function (e) {
                            }
                        });
                    }           

                    $.ajax({
                        type: "GET",
                        url: contextPath + "/personal/info",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function (data) {
                            if(data.crecode&&data.ccadr){
                                $('input[name="apunitname"]').attr("value",data.coname);
                                $('input[name="ccinfo"]').attr("value",data.name);
                                $('input[name="ccphone"]').attr("value",data.username);
                                $('input[name="fax"]').attr("value",data.fax);
                                $('input[name="zipcode"]').attr("value",data.zipcode);
                                $('input[name="crecode"]').attr("value",data.crecode);
                                $('input[name="ccadr"]').attr("value",data.ccadr);
                                $('input[name="writename"]').attr("value",data.writename);
                                $('input[name="apunitname"]').attr("disabled",true);
                                $('input[name="ccinfo"]').attr("disabled",true);
                                $('input[name="ccphone"]').attr("disabled",true);
                                $('input[name="fax"]').attr("disabled",true);
                                $('input[name="zipcode"]').attr("disabled",true);
                                $('input[name="crecode"]').attr("disabled",true);
                                $('input[name="ccadr"]').attr("disabled",true);
                                $('input[name="writename"]').attr("disabled",true);
                            }
                        },
                        error: function (e) {

                        }
                    });
                    $('input[name="writedate"]').attr("value",getNowFormatDate())

                    var ConstNewItems = new Object();

                    layero.find('input[name="shiplength"]').on("blur",function () {
                        var s = toDecimal2($(this).val());
                        if(s){
                            $('input[name="shiplength"]').val(s);
                        }else{
                            $('input[name="shiplength"]').val("");
                        }
                    });

                    layero.find('input[name="grosston"]').on("blur",function () {
                        var s = Math.round($(this).val());
                        if(s){
                            $('input[name="grosston"]').val(s);
                        }else{
                            $('input[name="grosston"]').val("");
                        }
                    });

                    layero.find('input[name="hostpower"]').on("blur",function () {
                        var s = toDecimal2($(this).val());
                        if(s){
                            $('input[name="hostpower"]').val(s);
                        }else{
                            $('input[name="hostpower"]').val("");
                        }
                    });

                    $('#download1').on('click',function () {
                        if( !ConstNewItems.info1adr) {
                            layer.msg('请先上传文件...', {time: 1000});
                        }
                    });

                    $('#download2').on('click',function () {
                        if( !ConstNewItems.info2adr) {
                            layer.msg('请先上传文件...', {time: 1000});
                        }
                    });

                    $('#download3').on('click',function () {
                        if( !ConstNewItems.info3adr) {
                            layer.msg('请先上传文件...', {time: 1000});
                        }
                    });

                    $('#download4').on('click',function () {
                        if( !ConstNewItems.info4adr) {
                            layer.msg('请先上传文件...', {time: 1000});
                        }
                    });

                    $.ajax({
                        type: "GET",
                        url: contextPath + "/personal/info",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function (data) {
                            var username = "const"+data.username; 
                            console.log(username);

                            upload.render({
                                elem: '#file1'
                                ,size: 20480
                                ,url: contextPath + '/upload?username=' + username + '&filenum=file1'
                                ,accept: 'file' //普通文件
                                , exts: 'zip|rar'
                                ,auto: true
                                ,before: function(obj){ //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
                                    layer.load(); //上传loading
                                }
                                , done: function (res, index, upload) { //上传后的回调
                                    layer.closeAll('loading');
                                    console.log(res);
                                    if(res.msg == '上传成功') {
                                        ConstNewItems.info1adr = res.data.url;
                                        $('#download1').css("visibility",'visible');
                                        $('#download1').attr("href",contextPath+"/download?file="+res.data.url);
                                        layer.msg('船检机构批准的有效图纸上传成功...', {time: 1000});
                                    }
                                }
                                ,error: function(index, upload){
                                    layer.closeAll('loading'); //关闭loading
                                }
                            });

                            upload.render({
                                elem: '#file2'
                                ,size: 20480
                                ,url: contextPath + '/upload?username=' + username + '&filenum=file2'
                                ,accept: 'file' //普通文件
                                , exts: 'zip|rar'
                                ,auto: true
                                ,before: function(obj){ //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
                                    layer.load(); //上传loading
                                }
                                , done: function (res, index, upload) { //上传后的回调
                                    layer.closeAll('loading');
                                    console.log(res);
                                    if(res.msg == '上传成功') {
                                        ConstNewItems.info2adr = res.data.url;
                                        $('#download2').css("visibility",'visible');
                                        $('#download2').attr("href",contextPath+"/download?file="+res.data.url);
                                        layer.msg('建造工艺文件上传成功...', {time: 1000});
                                    }
                                }
                                ,error: function(index, upload){
                                    layer.closeAll('loading'); //关闭loading
                                }
                            });

                            upload.render({
                                elem: '#file3'
                                ,size: 20480
                                ,url: contextPath + '/upload?username=' + username + '&filenum=file3'
                                ,accept: 'file' //普通文件
                                , exts: 'zip|rar'
                                ,auto: true
                                ,before: function(obj){ //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
                                    layer.load(); //上传loading
                                }
                                , done: function (res, index, upload) { //上传后的回调
                                    layer.closeAll('loading');
                                    console.log(res);
                                    if(res.msg == '上传成功') {
                                        ConstNewItems.info3adr = res.data.url;
                                        $('#download3').css("visibility",'visible');
                                        $('#download3').attr("href",contextPath+"/download?file="+res.data.url);
                                        layer.msg('船厂建造开工条件有关资料上传成功...', {time: 1000});
                                    }
                                }
                                ,error: function(index, upload){
                                    layer.closeAll('loading'); //关闭loading
                                }
                            });

                            upload.render({
                                elem: '#file4'
                                ,size: 20480
                                ,url: contextPath + '/upload?username=' + username + '&filenum=file4'
                                ,accept: 'file' //普通文件
                                , exts: 'zip|rar'
                                ,auto: true
                                ,before: function(obj){ //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
                                    layer.load(); //上传loading
                                }
                                , done: function (res, index, upload) { //上传后的回调
                                    layer.closeAll('loading');
                                    console.log(res);
                                    if(res.msg == '上传成功') {
                                        ConstNewItems.info4adr = res.data.url;
                                        $('#download4').css("visibility",'visible');
                                        $('#download4').attr("href",contextPath+"/download?file="+res.data.url);
                                        layer.msg('其他有关资料上传成功...', {time: 1000});
                                    }
                                }
                                ,error: function(index, upload){
                                    layer.closeAll('loading'); //关闭loading
                                }
                            });

                        },
                        error: function (e) {

                        }
                    });
                    
                    form.on('checkbox(info1)', function(data){
                        if(data.elem.checked){
                            $('#span1').html('船检机构批准的有效图纸&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;数量');
                            $('#span1').css("color","black");
                            $('input[name="info1num"]').css("visibility",'visible');
                            $('#file1').css("visibility",'visible');

                            ConstNewItems.info1 = true;
                        } else {
                            $('#span1').html('船检机构批准的有效图纸');
                            $('#span1').css("color","grey");
                            $('input[name="info1num"]').css("visibility",'hidden');
                            $('#file1').css("visibility",'hidden');
                            $('#download1').css("visibility",'hidden');

                            console.log(ConstNewItems.info1adr);
                            if(ConstNewItems.info1adr){
                                $.ajax({
                                    type:"GET",
                                    url:contextPath+"/deletefile?file="+ConstNewItems.info1adr,
                                    contentType: "application/json; charset=utf-8",
                                    dataType:"json",
                                    success:function (data) {
                                        if(data == "删除成功!"){
                                            layer.msg('上传文件已删除...',{time: 1000});

                                        } else {
                                            layer.msg(data, {
                                                time: false,
                                                btn:"确定",
                                                btnAlign: 'c'
                                            });
                                        }
                                    },
                                    error:function (e) {
                                    }
                                });
                            }

                            ConstNewItems.info1 = false;
                            ConstNewItems.info1num = 0;
                            ConstNewItems.info1adr = "";
                        }
                    });

                    form.on('checkbox(info2)', function(data){
                        if(data.elem.checked){
                            $('#span2').html('建造工艺文件&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;数量');
                            $('#span2').css("color","black");
                            $('input[name="info2num"]').css("visibility",'visible');
                            $('#file2').css("visibility",'visible');

                            ConstNewItems.info2 = true;
                        } else {
                            $('#span2').html('建造工艺文件');
                            $('#span2').css("color","grey");
                            $('input[name="info2num"]').css("visibility",'hidden');
                            $('#file2').css("visibility",'hidden');
                            $('#download2').css("visibility",'hidden');

                            if(ConstNewItems.info2adr){
                                $.ajax({
                                    type:"GET",
                                    url:contextPath+"/deletefile?file="+ConstNewItems.info2adr,
                                    contentType: "application/json; charset=utf-8",
                                    dataType:"json",
                                    success:function (data) {
                                        console.log(data);
                                        if(data == "删除成功!"){
                                            layer.msg('上传文件已删除...',{time: 1000});
                                        } else {
                                            layer.msg(data, {
                                                time: false,
                                                btn:"确定",
                                                btnAlign: 'c'
                                            });
                                        }
                                    },
                                    error:function (e) {
                                    }
                                });
                            }

                            ConstNewItems.info2 = false;
                            ConstNewItems.info2num = 0;
                            ConstNewItems.info2adr = "";
                        }
                    });

                    form.on('checkbox(info3)', function(data){
                        if(data.elem.checked){
                            $('#span3').html('船厂建造开工条件有关资料');
                            $('#span3').css("color","black");
                            $('#file3').css("visibility",'visible');

                            ConstNewItems.info3 = true;
                        } else {
                            $('#span3').html('船厂建造开工条件有关资料');
                            $('#span3').css("color","grey");
                            $('#file3').css("visibility",'hidden');
                            $('#download3').css("visibility",'hidden');

                            if(ConstNewItems.info3adr){
                                $.ajax({
                                    type:"GET",
                                    url:contextPath+"/deletefile?file="+ConstNewItems.info3adr,
                                    contentType: "application/json; charset=utf-8",
                                    dataType:"json",
                                    success:function (data) {
                                        console.log(data);
                                        if(data == "删除成功!"){
                                            layer.msg('上传文件已删除...',{time: 1000});
                                        } else {
                                            layer.msg(data, {
                                                time: false,
                                                btn:"确定",
                                                btnAlign: 'c'
                                            });
                                        }
                                    },
                                    error:function (e) {
                                    }
                                });
                            }

                            ConstNewItems.info3 = false;
                            ConstNewItems.info3adr = "";
                        }
                    });

                    form.on('checkbox(info4)', function(data){
                        if(data.elem.checked){
                            $('#span4').html('其他&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名称');
                            $('#span4').css("color","black");
                            $('input[name="info4name"]').css("visibility",'visible');
                            $('#file4').css("visibility",'visible');

                            ConstNewItems.info4 = true;
                        } else {
                            $('#span4').html('其他');
                            $('#span4').css("color","grey");
                            $('input[name="info4name"]').css("visibility",'hidden');
                            $('#file4').css("visibility",'hidden');
                            $('#download4').css("visibility",'hidden');

                            if(ConstNewItems.info4adr){
                                $.ajax({
                                    type:"GET",
                                    url:contextPath+"/deletefile?file="+ConstNewItems.info4adr,
                                    contentType: "application/json; charset=utf-8",
                                    dataType:"json",
                                    success:function (data) {
                                        console.log(data);
                                        if(data == "删除成功!"){
                                            layer.msg('上传文件已删除...',{time: 1000});
                                        } else {
                                            layer.msg(data, {
                                                time: false,
                                                btn:"确定",
                                                btnAlign:'c'
                                            });
                                        }
                                    },
                                    error:function (e) {
                                    }
                                });
                            }

                            ConstNewItems.info4 = false;
                            ConstNewItems.info4name = "";
                            ConstNewItems.info4adr = "";
                        }
                    });

                    //监听提交
                    form.on('submit(caseglyx)', function(data) {
                        $(this).attr('disabled','disabled');

                        ConstNewItems.shipname = data.field.shipname;
                        ConstNewItems.insptype = data.field.insptype;
                        ConstNewItems.shiplength = data.field.shiplength;
                        ConstNewItems.grosston = data.field.grosston;
                        ConstNewItems.hostpower = data.field.hostpower;
                        ConstNewItems.region = data.field.region;
                        ConstNewItems.shipstops = data.field.shipstops;
                        ConstNewItems.shiptype = data.field.shiptype;
                        ConstNewItems.designunit = data.field.designunit;
                        ConstNewItems.figurenum = data.field.figurenum;
                        ConstNewItems.approvalnum = data.field.approvalnum;
                        ConstNewItems.figuredate = data.field.figuredate;
                        ConstNewItems.schddate = data.field.schddate;
                        ConstNewItems.cdinfo = data.field.cdinfo;
                        ConstNewItems.ccpronum = data.field.ccpronum;
                        if(ConstNewItems.info1){
                            ConstNewItems.info1num = $('input[name="info1num"]').val();
                        } else{
                            ConstNewItems.info1 = false;
                            ConstNewItems.info1num = 0;
                            ConstNewItems.info1adr = "";
                        }
                        if(ConstNewItems.info2){
                            ConstNewItems.info2num = $('input[name="info2num"]').val();
                        } else{
                            ConstNewItems.info2 = false;
                            ConstNewItems.info2num = 0;
                            ConstNewItems.info2adr = "";
                        }
                        if(ConstNewItems.info3){

                        }else {
                            ConstNewItems.info3 = false;
                            ConstNewItems.info3adr = "";
                        }
                        if(ConstNewItems.info4){
                            ConstNewItems.info4name = $('input[name="info4name"]').val();
                        } else{
                            ConstNewItems.info4 = false;
                            ConstNewItems.info4name = "";
                            ConstNewItems.info4adr = "";
                        }
                        ConstNewItems.additional = data.field.additional;
                        ConstNewItems.apunitname = data.field.apunitname;
                        ConstNewItems.fax = data.field.fax;
                        ConstNewItems.zipcode = data.field.zipcode;
                        ConstNewItems.crecode = data.field.crecode;
                        ConstNewItems.ccadr = data.field.ccadr;
                        ConstNewItems.writename = data.field.writename;
                        ConstNewItems.ccinfo = data.field.ccinfo+"/"+data.field.ccphone;
                        ConstNewItems.remarks  = data.field.remarks;

                        console.log(JSON.stringify(ConstNewItems));

                        $.ajax({
                            type:"POST",
                            url:contextPath+"/project/const/new/cc",
                            contentType: "application/json; charset=utf-8",
                            data:JSON.stringify(ConstNewItems),
                            dataType:"json",
                            success:function (data) {
                                if(data.message == "创建成功!"){
                                    layer.msg('建造检验申请表创建成功!<br>页面将在1秒后刷新...');
                                    setTimeout(function(){window.location.reload();},1000);
                                } else {
                                    $('#suresubmitx').attr('disabled',false);
                                    layer.msg(data.message, {
                                        time: false,
                                        btn:"确定",
                                        btnAlign:'c'
                                    });
                                }
                            },
                            error:function (e) {
                            }
                        });
                        return false;
                    });

                },
                yes: function(index) {
                    console.log(index);
                },
                full: function(elem) {
                    var win = window.top === window.self ? window : parent.window;
                    $(win).on('resize', function() {
                        var $this = $(this);
                        elem.width($this.width()).height($this.height()).css({
                            top: 0,
                            left: 0
                        });
                        elem.children('div.layui-layer-content').height($this.height() - 95);
                    });
                }
            });
            form.render();
        });
    });

    $('.site-table tbody tr').on('click', function(event) {
        var $this = $(this);
        var $input = $this.children('td').eq(0).find('input');
        $input.on('ifChecked', function(e) {
            $this.css('background-color', '#EEEEEE');
        });
        $input.on('ifUnchecked', function(e) {
            $this.removeAttr('style');
        });
        $input.iCheck('toggle');
    }).find('input').each(function() {
        var $this = $(this);
        $this.on('ifChecked', function(e) {
            $this.parents('tr').css('background-color', '#EEEEEE');
        });
        $this.on('ifUnchecked', function(e) {
            $this.parents('tr').removeAttr('style');
        });
    });

    exports('ConstItemsList', {}); //注意，这里是模块输出的核心，模块名必须和use时的模块名一致
});